package me.zk.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Hello world!
 *
 */
public class RabbitMqTopicProducerDemo {
    public static void main( String[] args ) throws IOException, TimeoutException {
        // 创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");

        // 获取connection
        Connection connection = factory.newConnection();
        // 获取channel
        Channel channel = connection.createChannel();

        channel.exchangeDeclare("topic","topic");

        // 交换机名称，路由key，消息属性，消息
        for (int i = 0; i < 20; i++) {
            String s = "topic" + i;
            channel.basicPublish("topic","info.1",
                    MessageProperties.PERSISTENT_BASIC,s.getBytes());

        }


        channel.close();
        connection.close();

    }
}
